home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Programming / AmigaTalk / general / Object.st < prev    next >
Text File  |  2000-02-27  |  3KB  |  113 lines

  1. "-----------------------------------------------------------------"
  2. " Object Class is the Root of all other Classes in AmigaTalk.     "
  3. "-----------------------------------------------------------------"
  4.  
  5. Class Object
  6. [
  7.     == anObject
  8.       ^ <primitive 7 self anObject >
  9. |
  10.     ~~ x
  11.       ^ (self == x) not
  12. |
  13.     = x
  14.       ^ (self == x)              "Is the receiver equal to x??"
  15. |
  16.     ~= x
  17.       ^ (self = x) not           "Is the receiver NOT equal to x??"
  18. |
  19.     asString
  20.       ^ <primitive 152 (self class)> "Avoid recursion!"
  21.       "^ self class printString" "<<--Infinite recursive method."
  22. |
  23.     asSymbol
  24.       ^ self asString asSymbol   "Return the class a Symbol."
  25. |
  26.     class
  27.       ^ <primitive 1 self >
  28. |
  29.     copy
  30.       ^ self shallowCopy
  31. |
  32.     deepCopy  ! size newobj !
  33.       size <- <primitive 4 self>.
  34.  
  35.       (size < 0) 
  36.          ifTrue: [^ self] "if special just copy object"
  37.          ifFalse: [ newobj <- self class new.
  38.  
  39.       (1 to: size) do: [:i |
  40.             <primitive 112 newobj i ( <primitive 111 self i > copy ) > ].
  41.             ^ newobj ]
  42. |
  43.     do: aBlock     ! item !
  44.       item <- self first.
  45.  
  46.       ^ [item notNil] whileTrue:
  47.                       [aBlock value: item.  item <- self next]
  48. |
  49.     error: aString
  50.       <primitive 122 aString self>
  51. |
  52.     first
  53.       ^ self
  54. |
  55.     isKindOf: aClass ! objectClass !
  56.       objectClass <- self class.
  57.  
  58.       [objectClass notNil] whileTrue:
  59.              [(objectClass == aClass) ifTrue: [^ true].
  60.  
  61.                  objectClass <- objectClass superClass].
  62.       ^ false
  63. |
  64.     isMemberOf: aClass
  65.        ^ aClass == self class
  66. |
  67.     isNil
  68.        ^ false
  69. |
  70.     next
  71.        ^ nil
  72. |
  73.     notNil
  74.        ^ true
  75. |
  76.     print
  77.        <primitive 121 (self printString) >
  78. |
  79.     printString
  80.        ^ self asString
  81. |    
  82.     respondsTo: cmd
  83.        ^ self class respondsTo: cmd
  84. |    
  85.     shallowCopy ! size newobj !
  86.        size <- <primitive 4 self>.
  87.  
  88.        (size < 0) 
  89.          ifTrue: [^ self] "if special just copy object"
  90.          ifFalse: [ newobj <- self class new.
  91.  
  92.        (1 to: size) do: [:i |
  93.                <primitive 112 newobj i <primitive 111 self i > > ].
  94.  
  95.                           ^ newobj ]
  96. |
  97.    subclassResponsibility: methodString ! msg !
  98.      msg <- String new: 'Method ',methodString,' should be implemented in a SubClass!'.
  99.      ^ <primitive 181 13 msg 'User ERROR:' 'OKAY'>
  100. |
  101.    notImplemented: methodString ! msg ! 
  102.      msg <- String new: 'Method ',methodString,' NOT implemented!'.
  103.      ^ <primitive 181 13 msg 'User ERROR:' 'OKAY'>
  104. |
  105.    doesNotUnderstand: methodString ! msg !
  106.      msg <- String new: 'Method ',methodString,' NOT understood!'.
  107.      ^ <primitive 181 13 msg 'User ERROR:' 'OKAY'> 
  108. |
  109.    shouldNotImplement: methodString ! msg !
  110.      msg <- String new: 'Method ',methodString,' should NOT BE implemented!'.
  111.      ^ <primitive 181 13 msg 'User ERROR:' 'OKAY'>
  112. ]
  113.